package cn.itsource.web.controller;

import cn.itsource.domain.Employee;
import cn.itsource.result.JSONResult;
import cn.itsource.serivce.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**--------------------------------------------------------
登录相关
 --------------------------------------------------------**/
@RestController

public class LoginController {

    public static final String EMPLOYEE_IN_SESSION = "EMPLOYEE_IN_SESSION";

    @Autowired
    private IEmployeeService employeeService ;

    /** 登录 **/
    @RequestMapping("/login")
    public JSONResult login(String username , String password, HttpSession session){
        try {
            //执行登录
            Employee employee = employeeService.login(username,password);
            //登录存放session
            session.setAttribute(EMPLOYEE_IN_SESSION, employee);
            return new JSONResult() ;
        }catch (Exception e){
            e.printStackTrace();
            return new JSONResult(false,"错误那") ;
        }
    }
}
